package com.jeecms.wicool.manager.util.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.util.DictionaryDao;
import com.jeecms.wicool.entity.util.Dictionary2;
import com.jeecms.wicool.manager.util.DictionaryMng;

@Service
@Transactional
public class DictionaryMngImpl implements DictionaryMng {
	
	public void init(){
	}
	@Transactional(readOnly = true)
	public Pagination getPage(String typeCode,int pageNo, int pageSize) {
		Pagination page = dao.getPage(typeCode,pageNo, pageSize);
		return page;
	}
	
	@Transactional(readOnly = true)
	public List<Dictionary2> getList(String typeCode){
		return dao.getList(typeCode);
	}
	
	@Transactional(readOnly = true)
	public List<String> getTypeList(){
		return dao.getTypeList();
	}

	@Transactional(readOnly = true)
	public Dictionary2 findById(Integer id) {
		Dictionary2 entity = dao.findById(id);
		return entity;
	}
	
	@Transactional(readOnly = true)
	public Dictionary2 findByValue(String typeCode,String dicName){
		Dictionary2 entity = dao.findByValue(typeCode,dicName);
		return entity;
	}
	@Transactional(readOnly = true)
	public Dictionary2 findByDicCode(String typeCode,Short dicCode){
		Dictionary2 entity = dao.findByDicCode(typeCode, dicCode);
		return entity;
	}
	public Dictionary2 save(Dictionary2 bean) {
		dao.save(bean);
		return bean;
	}

	public Dictionary2 update(Dictionary2 bean) {
		Updater<Dictionary2> updater = new Updater<Dictionary2>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	public Dictionary2 deleteById(Integer id) {
		Dictionary2 bean = dao.deleteById(id);
		return bean;
	}
	
	public Dictionary2[] deleteByIds(Integer[] ids) {
		Dictionary2[] beans = new Dictionary2[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	
	public boolean dicDeplicateValue(String dicName, String typeCode) {
		return dao.countByValue(dicName,typeCode) > 0;
	}

	private DictionaryDao dao;

	@Autowired
	public void setDao(DictionaryDao dao) {
		this.dao = dao;
	}
}